package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.acticle.domain.Destination;
import cn.wolfcode.luowowo.acticle.domain.Strategy;
import cn.wolfcode.luowowo.acticle.query.DestinationQueryObject;
import cn.wolfcode.luowowo.acticle.query.StrategyQueryObject;
import cn.wolfcode.luowowo.acticle.service.IDestinationService;
import cn.wolfcode.luowowo.acticle.service.IStrategyService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 大攻略资源管理器
 */
@Controller
@RequestMapping("/strategy")
public class StrategyController {
    @Reference
    private IStrategyService strategyService;
    @Reference
    private IDestinationService destinationService;
    //大攻略列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyQueryObject qo){
        PageInfo pageInfo = strategyService .query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "strategy/list";
    }
    //根据deep获取目的地
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(@ModelAttribute("qo") DestinationQueryObject qo){
        List<Destination> destinations = destinationService.getDestinationByDeep(3);
        return destinations;
    }
    //保存攻略
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Strategy strategy){
        strategyService.saveOrUpdate(strategy);
        return new AjaxResult();
    }
    //删除攻略
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        strategyService.delete(id);
        return new AjaxResult();
    }
}
